package learn.Thread;

//public class ThreadPrintABC {
//    public static void main(String[] args) throws InterruptedException {
//        Thread a = new ThreadPrint(0,"a");
//        Thread b = new ThreadPrint(1,"b");
//        Thread c = new ThreadPrint(2,"c");
//        a.start();
//
//        b.start();
//
//        c.start();
//    }
//}

class ThreadPrint extends Thread{
    private static Object lock = new Object();
    private static int count = 0;
    private int flag;
    private String value;

    public ThreadPrint(int flag,String value){
        this.flag = flag;
        this.value = value;
    }
    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {
            synchronized (lock){
                while(count%3!=flag){
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(value);
                count++;
                lock.notifyAll();
            }
        }
    }
}
